/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.vacoor.ui.qq.password;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JDialog;
import javax.swing.JPanel;

/**
 *
 * @author Vacoor
 */
public class ScreenKeyboard extends JDialog {

	private static final long serialVersionUID = 1L;
	BufferedImage img;
    JPanel panel;

    public ScreenKeyboard() {
        try {
            img = ImageIO.read(getClass().getClassLoader().getResource("images/ScreenKeyboard.png"));
        } catch (IOException e) {
            System.out.println("读取出错");
        }
        panel = new JPanel() {
			private static final long serialVersionUID = 1L;

			@Override
            public void paintComponent(Graphics g) {
                super.paintComponent(g);
                g.drawImage(img, 0, 0, this);
            }
        };
        panel.setPreferredSize(new Dimension(img.getWidth(), img.getHeight()));
        panel.setMinimumSize(new Dimension(img.getWidth(), img.getHeight()));
        this.add(panel);
        this.setUndecorated(true);
        this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
        this.pack();
        this.setAlwaysOnTop(true);
        panel.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                setVisible(false);
            }

            @Override
            public void mouseExited(MouseEvent e) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException ex) {
                }
                setVisible(false);
            }
        });
    }

    public void showScrKeyboard(int x, int y) {
        this.setLocation(x, y);
        this.setVisible(true);
    }
}
